(()=>{"use strict";class t{constructor(){this.hd=new Map}on(t,e){let o=this.hd.get(t);o||(o=[],this.hd.set(t,o)),o.push(e)}off(t,e){let o=this.hd.get(t);if(!o)return;const i=o.findIndex((t=>t===e));i>-1&&o.splice(i,1)}emit(t,e){let o=this.hd.get(t);if(o)for(const t of o)try{t.apply(this,e)}catch(t){}}}const e={};function o(o,i=!0){let s=e[o];return!s&&i&&(s=e[o]={compGenerators:[],events:new t}),s}const i={defineExtComp:(t,e)=>(t.forEach((t=>{!function(t,e){const i=o(t);i.compGenerators.push(e),i.events.emit("Define",[e,i])}(t,e)})),e),destroyExtComp(t,e){t.forEach((t=>{!function(t,e){const i=o(t),s=i.compGenerators,n=s.findIndex((t=>t===e));n>-1&&(s.splice(n,1),i.events.emit("Destroy",[e,i]))}(t,e)}))}};function s(t){t.forEach(((t,e)=>t.index=e)),t.sort(((e,o)=>{const i=e.rank?1e5*e.rank:t.length-e.index;return(o.rank?1e5*o.rank:t.length-o.index)-i}))}class n extends HTMLElement{get pointKey(){return this.dataset.pointKey}constructor(){super(),this.inited=!1,this.already=!1,this.generatorToComps=new Map,this.comps=[],this.init=()=>{let t=this.querySelector(":scope>.ws-extension-point__comps-container");if(t||(t=document.createElement("div"),t.classList.add("ws-extension-point__comps-container"),this.appendChild(t)),this.compsContainer=t,this.pointCompsInfo=o(this.pointKey),this.pointCompsInfo.events.on("Define",this.onDefineExtComp),this.pointCompsInfo.events.on("Destroy",this.onDestroyExtComp),this.inited=!0,!this.provide)if("1"===this.dataset.noProvide)this.provide={props:{},export:{}};else if(this.dataset.provide)try{this.provide=JSON.parse(this.dataset.provide),this.provide.props||(this.provide.props={}),this.provide.export||(this.provide.export={})}catch(t){setTimeout((()=>{throw t.message=`[data-provide="${this.dataset.provide}"] json parse failed: ${t.message}`,t}))}this.provide&&this.ready()},this.onDefineExtComp=t=>{if(!this.provide)return;const e=this.insComp(t);e&&(s(this.comps),this.render(e),this.reRankDom(),this.updateCompIsEmpty())},this.onDestroyExtComp=t=>{const e=this.generatorToComps.get(t);if(this.generatorToComps.delete(t),e){const t=this.comps.findIndex((t=>t===e));t>-1&&(this.comps.splice(t,1),s(this.comps)),this.destroyExtComp(e),this.updateCompIsEmpty()}},this.render=t=>{var e;const o=t.__comp.__el;let i=t.render(o);return i.comp=t,t.__comp.__el=i,o&&o!==i&&(o.comp&&delete o.comp,null===(e=o.parentElement)||void 0===e||e.removeChild(o)),i},this.compProvide={props:new Proxy({},{get:(t,e,o)=>this.provide.props[e]}),export:new Proxy({},{get:(t,e,o)=>(...t)=>{var o,i;return null===(i=null===(o=this.provide.export)||void 0===o?void 0:o[e])||void 0===i?void 0:i.call(o,...t)}})}}connectedCallback(){if(!this.pointKey)throw new Error('The attr "data-point-key" must be defined');if(!document.head.__WsExtensionPointStyle){const t=document.head.__WsExtensionPointStyle=document.createElement("style");t.innerHTML=`\n ${this.tagName.toLowerCase()} [content="empty"]{display:var(--emptyContentDisplay, "") !important}\n ${this.tagName.toLowerCase()} .ws-extension-point__comps-container{display:var(--extCompContainerDisplay, "none") !important}`,document.head.appendChild(t)}"1"===this.dataset.inited?setTimeout(this.init,0):(this.dataset.inited="1",this.init())}ready(){if(this.inited&&!this.already&&this.provide){this.already=!0;for(const t of this.pointCompsInfo.compGenerators)this.insComp(t);s(this.comps),this.renderAll(),this.dispatchEvent(new CustomEvent("ready"))}}insComp(t){const e=function(t,e){let o=e(t);if(!o)return null;const i=new Proxy(o,{get:(t,i,s)=>{var n,r;if("__compGenerator"===i)return e;if("__comp"===i)return o;const p=null===(n=o.__data)||void 0===n?void 0:n[i];if(void 0!==p)return p;const a=null===(r=o.methods)||void 0===r?void 0:r[i];return void 0!==a?a:o[i]},set:(t,e,i,s)=>("__data"===e?o.__data=i:o.__data[e]=i,!0)});if(o.data&&(o.data=o.data.bind(i)),o.methods){const t=o.methods;Object.keys(t).forEach((e=>{const s=t[e];"function"==typeof s&&(o.methods[e]=s.bind(i))}))}return Object.keys(o).forEach((t=>{const e=o[t];"function"==typeof e&&(o[t]=e.bind(i))})),i}({pointKey:this.pointKey,provide:this.compProvide},t);return e?(this.generatorToComps.set(t,e),this.comps.push(e),e.__comp.__data||(e.__comp.data?e.__comp.__data=e.__comp.data():e.__comp.__data={}),e):null}destroyExtComp(t){var e,o;try{null===(e=t.destroyed)||void 0===e||e.call(t)}catch(t){}const i=t.__comp.__el;i&&(i.comp&&delete i.comp,null===(o=i.parentElement)||void 0===o||o.removeChild(i),delete t.__comp.__el)}disconnectedCallback(){var t,e,o;for(null===(t=this.pointCompsInfo)||void 0===t||t.events.off("Define",this.onDefineExtComp),null===(e=this.pointCompsInfo)||void 0===e||e.events.off("Destroy",this.onDestroyExtComp);null===(o=this.compsContainer)||void 0===o?void 0:o.firstElementChild;)this.compsContainer.removeChild(this.compsContainer.firstElementChild);this.generatorToComps.forEach((t=>{this.destroyExtComp(t)})),this.generatorToComps.clear(),this.comps.length=0,this.pointCompsInfo=null}renderAll(){this.already&&(this.comps.forEach(this.render),this.reRankDom(),this.updateCompIsEmpty())}reRankDom(){for(let t=0;t=this.comps.length;t--){const e=this.compsContainer.children.item(t);e&&this.compsContainer.removeChild(e)}}updateCompIsEmpty(){this.comps.length?this.style.cssText="--emptyContentDisplay:none;--extCompContainerDisplay:;":this.style.cssText="--emptyContentDisplay:;--extCompContainerDisplay:none;"}}var r,p,a;a="ws-extension-point",customElements.get(a)||customElements.define(a,n),null===(p=(r=window).__triggerSDKLoad)||void 0===p||p.call(r,"ui-extension-points",i)})();